package com.gy.edu.examination;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.gy.edu.R;
import com.gy.edu.base.BaseFragment;
import com.gy.edu.examination.adapter.ExaminationAskAdapter;
import com.gy.edu.examination.adapter.ExaminationReportAdapter;
import com.gy.edu.util.AnimUtil;

/**
 * 作者：gy on 16/12/21
 * 说明：微考试
 */
public class ExaminationHomeFragment extends BaseFragment{

    private TextView tvAsk,tvReport;
    private ListView listAsk,listReport;
    private ExaminationAskAdapter askAdapter;
    private ExaminationReportAdapter reportAdapter;


    @Override
    protected View setView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_examination_home,null);
        setTitleMsg("微考试");
        _baseBack.setVisibility(View.INVISIBLE);
        return view;
    }

    @Override
    protected void initView() {
        tvAsk = (TextView) _rootView.findViewById(R.id.examination_tv_ask);
        tvReport = (TextView) _rootView.findViewById(R.id.examination_tv_report);
        listAsk = (ListView) _rootView.findViewById(R.id.examination_list_ask);
        listReport = (ListView) _rootView.findViewById(R.id.examination_list_report);
    }

    @Override
    protected void initData() {
        askAdapter = new ExaminationAskAdapter(mContext);
        reportAdapter = new ExaminationReportAdapter(mContext);
    }

    @Override
    protected void setListener() {
        super.setListener();
        tvAsk.setOnClickListener(this);
        tvReport.setOnClickListener(this);

        listAsk.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(mContext,AskDetailActivity.class);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(getActivity());
            }
        });
        listReport.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(mContext,ReportDetailActivity.class);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(getActivity());
            }
        });
    }

    @Override
    protected void fillData() {
        super.fillData();
        listAsk.setAdapter(askAdapter);
        listReport.setAdapter(reportAdapter);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.examination_tv_ask:
                tvAsk.setBackgroundResource(R.mipmap.tap_left);
                tvReport.setBackgroundResource(R.mipmap.tap_not_right);
                tvAsk.setTextColor(getResources().getColor(R.color.white));
                tvReport.setTextColor(getResources().getColor(R.color.title_bg));
                listAsk.setVisibility(View.VISIBLE);
                listReport.setVisibility(View.GONE);
                break;
            case R.id.examination_tv_report:
                tvAsk.setBackgroundResource(R.mipmap.tap_not_left);
                tvReport.setBackgroundResource(R.mipmap.tap_right);
                tvAsk.setTextColor(getResources().getColor(R.color.title_bg));
                tvReport.setTextColor(getResources().getColor(R.color.white));
                listAsk.setVisibility(View.GONE);
                listReport.setVisibility(View.VISIBLE);
                break;
        }
    }
}
